PREFIX         =./lib
LIBNAME        =myblue
APP_NAME       =blue

CFLAGS         += -I ./inc/ $(shell pkg-config --cflags dbus-1) 
LDFLAGS        += -L${PREFIX} -l${LIBNAME} $(shell pkg-config --libs dbus-1) 

SRC_DIR        = ./src
SRC_MAIN       = $(SRC_DIR)/main.c
SRC_ALL        = $(wildcard $(SRC_DIR)/*.c)
SRC_LIB        = $(filter-out $(SRC_MAIN), $(SRC_ALL))

all:static_lib run 

run:
	gcc ${CFLAGS} ${SRC_MAIN} -o ${APP_NAME} ${LDFLAGS} -lmosquitto -lpthread

static_lib:
	mkdir -p ${PREFIX}
	gcc ${CFLAGS} -c ${SRC_LIB}
	ar -rcs lib${LIBNAME}.a *.o
	mv lib${LIBNAME}.a ${PREFIX}

clean:distclean
	rm -f ${APP_NAME} *.log 
	rm -f ${PREFIX}/lib${LIBNAME}.a 
distclean:
	rm -f *.o
